# The template generates jobs that trigger child pipelines for gems vendored in the main GitLab project under `gems/`.
#
# Inputs:
# - `gem_name`: The name of the gem, i.e. if the gem is located at `gems/gitlab-rspec`, `gem_name` should be set to `gitlab-rspec`.
# - `gem_path_prefix`: The prefix of the gem path, i.e. if the gem is located at `vendor/gems/gitlab-rspec`, `gem_path_prefix` should be set to `vendor/gems/`. Defaults to `gems/`.
spec:
  inputs:
    gem_name:
    gem_path_prefix:
      default: "gems/"
---
.gems:rules:$[[inputs.gem_name]]:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "schedule" && $SCHEDULE_TYPE == "maintenance"'
    - if: '$CI_MERGE_REQUEST_EVENT_TYPE == "merged_result" || $CI_MERGE_REQUEST_EVENT_TYPE == "detached"'
      changes:
        - "$[[inputs.gem_path_prefix]]$[[inputs.gem_name]]/**/*"
        - ".gitlab/ci/gitlab-gems.gitlab-ci.yml"
        - ".gitlab/ci/vendored-gems.gitlab-ci.yml"
        - ".gitlab/ci/templates/gem.gitlab-ci.yml"
        - "gems/gem.gitlab-ci.yml"
        # Ensure new cop in the monolith don't break internal gems Rubocop checks: https://gitlab.com/gitlab-org/gitlab/-/issues/419915
        - ".rubocop.yml"
        - "rubocop/**/*"
        - ".rubocop_todo/**/*"


gems $[[inputs.gem_name]]:
  extends: ".gems:rules:$[[inputs.gem_name]]"
  needs: []
  trigger:
    include: "$[[inputs.gem_path_prefix]]$[[inputs.gem_name]]/.gitlab-ci.yml"
    strategy: depend
  inherit:
    variables: false
